<template>
  <div class="chart-container" ref="chartContainer"></div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: 'StoneType',
  data() {
    return {
      chart: null,
      typeData: [
        { name: '自然风光', value: 18 },
        { name: '历史文化', value: 12 },
        { name: '宗教圣地', value: 8 },
        { name: '古镇古城', value: 4 },
        { name: '博物馆', value: 3 },
        { name: '主题公园', value: 2 },
        { name: '其他', value: 1 }
      ]
    }
  },
  mounted() {
    this.initChart()
    window.addEventListener('resize', this.resizeChart)
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.resizeChart)
    this.chart && this.chart.dispose()
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$refs.chartContainer, null, {
        renderer: 'canvas'
      })
      this.updateChart()
    },
    updateChart() {
      const option = {
        backgroundColor: 'transparent',
        title: {
          text: '5A级景区类型分布',
          subtext: '数据来源：文化和旅游部',
          left: 'center',
          textStyle: {
            color: '#8B4513',
            fontSize: 16,
            fontWeight: 'normal'
          },
          subtextStyle: {
            color: '#8B4513',
            fontSize: 12
          }
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c}个 ({d}%)',
          backgroundColor: 'rgba(255, 255, 255, 0.9)',
          borderColor: '#8B4513',
          textStyle: {
            color: '#8B4513'
          }
        },
        legend: {
          orient: 'vertical',
          left: 'left',
          textStyle: {
            color: '#8B4513'
          }
        },
        series: [
          {
            name: '景区类型',
            type: 'pie',
            radius: ['40%', '70%'],
            center: ['50%', '60%'],
            data: this.typeData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            },
            label: {
              show: true,
              formatter: '{b}: {c}个',
              color: '#8B4513'
            },
            labelLine: {
              lineStyle: {
                color: '#8B4513'
              }
            },
            itemStyle: {
              color: function(params) {
                const colorList = [
                  '#8B4513', '#A0522D', '#B8860B', '#CD853F',
                  '#D2691E', '#DEB887', '#F4A460'
                ]
                return colorList[params.dataIndex]
              }
            }
          }
        ]
      }

      this.chart.setOption(option)
    },
    resizeChart() {
      this.chart && this.chart.resize()
    }
  }
}
</script>

<style scoped>
.chart-container {
  width: 100%;
  height: 100%;
}
</style> 